<template>
  <div>
    <el-form inline :model="queryData" ref="queryData" class="query-form">
      <el-form-item label="企业名称:" prop="name">
        <el-input v-model="queryData.name" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('name')"/>
      </el-form-item>
      <el-form-item label="法人姓名:" prop="legalPerson">
        <el-input v-model="queryData.legalPerson" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('legalPerson')"/>
      </el-form-item>
      <el-form-item label="申请时间:" prop="createTime">
        <el-date-picker v-model="queryData.createTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 200px" clearable @clear="formClear('createTime')"></el-date-picker>
      </el-form-item>
      <el-form-item label="状态:" prop="checkState">
        <el-select v-model="queryData.checkState" placeholder="请选择" clearable @clear="formClear('checkState')">
          <el-option v-for="(item, index) in checkState" :key="index" :label="item" :value="index"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查 询</el-button>
        <el-button @click="onReset">重 置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableList" border style="width: 100%;">
      <el-table-column prop="id" label="审核ID" align="center" width="100"/>
      <el-table-column prop="name" label="企业名称" align="center" show-overflow-tooltip/>
      <el-table-column prop="creditCode" label="纳税识别号" align="center"/>
      <el-table-column prop="legalPerson" label="法人姓名" align="center"/>
      <el-table-column prop="contactsName" label="申请人姓名" align="center"/>
      <el-table-column prop="contactsPhone" label="联系方式" align="center"/>
      <el-table-column prop="checkState" label="审核状态" align="center" :formatter="(row) => checkState[row.checkState - 0]"/>
      <el-table-column prop="createTime" label="申请时间" align="center"/>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="{row}">
          <el-button type="text" @click="lookOverEvent(row)">查 看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Paging v-model="queryData" @change="getRequest"></Paging>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    computed: {
      ...mapGetters(['confirm'])
    },
    name: 'enterpriseAudit',
    data() {
      return {
        checkState: ['待审核', '同意', '拒绝'],
        tableList: [],
        queryData: {
          pageNum: 1,
          pageSize: 10,
          total: 0,
          createTime: null
        }
      }
    },

    beforeMount() {
      this.getRequest()
    },
    methods: {
      lookOverEvent (row) {
        this.$router.push(`/enterpriseManage/enterpriseAuditDetail?detailId=${row.id}`)
      },
      /**
       * 重置事件
       */
      onReset() {
        this.$refs['queryData'].resetFields()
        this.getRequest()
      },
      /**
       * 查询条件提交事件
       */
      onSubmit() {
        console.log('---------------------------')
        this.queryData.pageNum = 1
        this.getRequest()
      },
      /**
       * 列表请求事件
       */
      async getRequest() {
        const formData = JSON.parse(JSON.stringify(this.queryData))
        const res = await this.$ajax.get('/wx/enterpriseCertification/list', { params: formData })
        this.queryData.total = res.total
        this.tableList = res.rows
      },
      /**
       * form置空事件
       */
      formClear(key) {
        this.queryData[key] = null
        this.onSubmit()
      }
    }
  }
</script>

<style scoped>

</style>
